<?php

namespace app\admin\model;

use think\Db;
use think\Model;

class StandmoneyModel extends Model
{

    // 设置数据表（不含前缀）
    protected $name = 'stand_money';
    // 设置当前模型对应的完整数据表名称
    protected $table = 'ld_stand_money';

    public function __construct($data = [])
    {
        parent::__construct($data);
    }


    /**
     * @param 收费标准列表
     */
    public function problist($where,$page,$limit){
        $query = Db::name($this->name)->where($where)->page($page)->limit($limit)->order('addTime desc')->field('id,title,enable,addTime,updateTime')->select();
        return $query;
    }


    public function county($where){
        $query = Db::name($this->name)->where($where)->count();
        return $query;
    }


    /**
     * @param 添加收费标准
     */
    public function polist($data){
        $query = Db::name($this->name)->insert($data);
        return $query;
    }

    /**
     * @param $id
     * @param 获取当前收费标准
     */
    public function datalist($id){
        $query = Db::name($this->name)->where('id',$id)->find();
        return $query;
    }

    /**
     * @param $where
     * @param $data
     * @param 修改收费标准
     */
    public function edisont($where,$data){
        $query = Db::name($this->name)->where($where)->update($data);
        return $query;
    }


    /**
     * @param 获取平台列表
     */
    public function datalis(){
        $query = Db::name($this->name)->where('state','eq',1)->field('id,titname')->select();
        return $query;
    }


    /**
     * @param $where
     * @param 获取当前收费标准
     */
    public function exbut($where){
        $query = Db::name($this->name)->where($where)->find();
        return $query;
    }


    /**
     * @param $where
     * @param $data
     * @param 禁用、启用
     */
    public function eidtion($where,$data){
        $query = Db::name($this->name)->where($where)->update($data);
        return $query;
    }


    /**
     * @param $id
     * @param 删除收费标准
     */
    public function del($where){
        Db::startTrans();
        try{
            $query = Db::name($this->name)->where($where)->delete();
            // 提交事务
            Db::commit();
            return $query;
        } catch (\Exception $e) {
            // 回滚事务
            Db::rollback();
            return false;
        }
    }


    /**
     * @param $where
     * @param 获取收费列表
     */
    public function listmoney($where){
        $query = Db::name($this->name)->where($where)->order('addTime asc')->select();
        return $query;
    }

}